<!-- 首页 -->
<template>
	<view class="container">
		<van-picker :default-index="current" :columns="columns" @change="handleChange" :loading="pickerLoading" ref="picker">
		</van-picker>
	</view>
</template>

<script>
	import {
		bustList
	} from "@/api/mine/auth.js"
	export default {
		name: "",
		props:{
			value:{
				type:String
			},
			isConfirm:{
				type:Boolean
			}
		},
		data() {
			return {
				current: 0,
				columns: [],
				pickerLoading:false
			}
		},
		watch: {
			isConfirm:{
				immediate: true,
				handler(val){
					if(val){
						let values = this.$refs['picker'].getValues()
						this.$emit('input', values[0])
						
					}
				}
			},
			value: {
				immediate: true,
				async handler(value) {
					if (!this.columns.length) {
						await this.getList()
					}
					if (value) {
						setTimeout(() => {
							this.current = this.columns.indexOf(value)
						}, 100)
					}
				}
			}
		},
		methods: {
			async getList() {
				this.pickerLoading = true
				await bustList().then(res => {
					let {
						data
					} = res
					this.columns = data?.map(item => item.title) ?? []
					this.pickerLoading = false
				})
			},
			handleChange(picker) {
				let {
					detail: {
						value
					}
				} = picker
				this.$emit('input', value)
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {}
</style>